#!/bin/bash

ns=nacos

if [[ "$1" == "install" ]]; then
    kubectl create namespace ${ns}

    ## replace it after https://github.com/kubesphere/helm-charts/pull/128 merged
    ## expected place is https://charts.kubesphere.io/test
    rm -rf nacos
    git clone https://gitee.com/linuxsuren/helm-charts-1 nacos
    cd nacos && git checkout nacos && cd src/test/nacos && helm install ${ns} . --namespace ${ns} --set global.mode=cluster --set service.nodePort= 

    NODE_PORT=$(kubectl get --namespace ${ns} -o jsonpath="{.spec.ports[0].nodePort}" services  nacos-cs)
    NODE_IP=$(kubectl get nodes --namespace ${ns} -o jsonpath="{.items[0].status.addresses[0].address}")
    echo "nacos address is http://${NODE_IP}:${NODE_PORT}/nacos, default user/password is nacos/nacos"
elif [[ "$1" == "uninstall" ]]; then
    helm delete --namespace ${ns} ${ns}
    kubectl delete namespace ${ns}
else
    echo "Usage: ./nacos.sh (install|uninstall)"
fi
